package com.funsport.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.funsport.entity.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * 用户角色关联Mapper
 */
@Mapper
public interface UserRoleMapper extends BaseMapper<UserRole> {
    
    /**
     * 删除用户的所有角色
     */
    @Delete("DELETE FROM tb_user_role WHERE user_id = #{userId}")
    int deleteByUserId(Long userId);
    
    /**
     * 删除用户的指定角色
     */
    @Delete("DELETE FROM tb_user_role WHERE user_id = #{userId} AND role_id = #{roleId}")
    int deleteByUserIdAndRoleId(Long userId, Long roleId);
    
    /**
     * 获取用户的角色ID列表
     */
    @Select("SELECT role_id FROM tb_user_role WHERE user_id = #{userId}")
    List<Long> selectRoleIdsByUserId(Long userId);
}

